<?php
require('src/OrdenCompra.class.php');
require('src/Producto.class.php');

$id   	= (isset($_GET['id'])) ? $_GET['id']:0;
?>

<script  type="text/javascript">
var idOdc           = <?php echo $id; ?>;
var tipoInsertar    = 0;
var objTabla        = {};
var i               = 0;
var iGlobal         = 0;
var esAdd           = false;
var data            = {  prod   : "",
                         prodId : 0,
                         cant   : 0,
                         idEle  : 0,
                         iocId  : 0
                        };
var ioc             = null;

$(document).ready(function(){
   $.ajax({
        url: 'src/ordencompra.php?modo=7',
        data: "submit=&odcId="+idOdc,
        dataType: "json",
        success: function(data) {
             var pro = (typeof data.d) == 'string' ? eval('(' + data.d + ')') :  data;
             $("#lblCodigo").html(pro[0].odcCod);
             $("#lblRif").html(pro[0].cirif);
             $("#lblRazonS").html(pro[0].razonS);
             $("#lblDireccion").html(pro[0].direcF);
             $("#lblTelefono").html(pro[0].tlfOfi);                          
             iocArray = pro[1];
             agregarRow();


        }
    });
}); 

function agregarRow(){
    for(var x = 0, n = iocArray.length; x < n ; x++){
        data = { prod   : iocArray[x].map_nombre,
                 prodId : iocArray[x].map_id,
                 cant   : iocArray[x].ioc_cant,
                 cantRec: iocArray[x].ioc_cantrecibida,
                 idEle  : 0,
                 iocId  : iocArray[x].ioc_id
                };
        $('#idIoc').val(iocArray[x].ioc_id);
        agregar(data);

    }   
}

function agregar (data) {
    i++;
    //agregarObj(i, data.prodId, data.cant, data.prod, 1, data.idEle, data.iocId);
    var tds = "<tr id ='tr"+i+"'><td>"+i+"</td>"+
                      "<td>"+data.prod+"</td>"+
                      "<td>"+data.cant+"</td>"+
                      "<td>"+data.cantRec+"</td>"+
                      "<td><input id='cantR' type='text' name='cantR[]'  style='width:40px;' class='validate[required,number] text-input'/>"+
                      "<input id='ioc' type='hidden' name='ioc[]' value='"+data.iocId+"' />"+
                      "<input id='cantP' type='hidden' name='cantP[]' value='"+data.cantRec+"' />"+
                      "<input id='map' type='hidden' name='map[]' value='"+data.prodId+"' /></td></tr>";

    $("#tbl  > tbody:last").append(tds);

}
/*
function agregarObj (i,prodId,cant,prod,accion,idEle, idIoc){
    var idElemento = (tipoInsertar==0)? 0:idEle;
    objTabla[i+"elemento"] = idElemento+"#"+prodId+"#"+cant+"#"+prod+"#"+accion+"#"+idIoc;

}*/

</script>
<div id="stylized" class="myform" style="margin:20px auto;">

<div id="material_comprado"  > </div>  
    
    <h2>Orden de Compra</h2>
    <table>
        <tr>
            <td><span class="title">C&oacute;digo: </span><span id="lblCodigo" class="text"></span></td>
        </tr>
        <tr>
            <td><span class="title">R.I.F.: </span><span id="lblRif" class="text"></span></td>
            <td><span class="title">Raz&oacute;n Social: </span><span id="lblRazonS" class="text"></span></td>
        </tr>
        <tr>
            <td><span class="title">Direcci&oacute;n Fiscal: </span><span id="lblDireccion" class="text"></span></td>
            <td></td>
        </tr>
        <tr>
            <td><span class="title">T&eacute;lefono: </span><span id="lblTelefono" class="text"></span></td>
            <td></td>
        </tr>
    </table>
    <p></p>

    </br>
    <form id="formID1">
        <table class="doc" id="tbl" >
            <thead>
                <tr>
                    <th>&Iacute;tem</th>
                    <th>Producto</th>
                    <th>Cantidad por Recibir</th>
                    <th>Cant. Procesada</th>
                    <th>Cant. Recibida</th>
                </tr>            
            </thead>
            <tbody>

            </tbody>
        </table>
    </form>
</div>




<!--<button type="button" class="boton" i>Save</button>
<input class="boton"  type="button" id="salvar" value="Salvar" />
<div class="spacer"></div>
</form>-->
</div>

